<?php include $this->admin_tpl('meta');?>
<title>添加栏目 - YzmCMS内容管理系统</title>
</head>
<body>
<div class="page-container">
	<form class="form form-horizontal" method="" action="" onsubmit="return dosub(this)">
		<div id="tab_system" class="HuiTab">
			<div class="tabBar cl"><span>基本选项</span><span>模板设置</span><span>SEO设置</span><span>其他设置</span></div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>选择模型：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
						<select name="modelid" class="select" onchange="javascript:yzm_change_template(this.value)">
						  <?php 
						      foreach($modelinfo as $val){
									$str = $modelid==$val['modelid'] ? ' selected="selected" ' : '';
									echo '<option value="'.$val['modelid'].'"'.$str.'>'.$val['name'].'('.$val['alias'].')</option>';
							  }
							  if(!$modelinfo) echo '<option value="">暂无模型</option>';
						  ?>
						</select>
						</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>上级栏目：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<span class="select-box">
						 <?php echo select_category('parentid', $catid, '', 0, '', false, false); ?>
						</span>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>栏目名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="catname" value="" class="input-text"  onblur="yzmcms_pinyin()" placeholder="例如：新闻中心">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>英文目录：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="catdir" value="" class="input-text" placeholder="支持多级目录，如： xinwen/guonei" > 
						<i class="yzm-iconfont yzm-iconshuaxin" style="position:absolute;top:5px;right:23px;cursor:pointer;" title="继承父级目录" onclick="change_dir()"></i>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目图片：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input class="input-text" type="text" name="catimg" style="width:400px" id="uploadfile" onmouseover="yzm_img_preview('uploadfile', this.value)"  onmouseout="layer.closeAll();">
						<a href="javascript:;" onclick="yzm_upload_att('<?php echo U('attachment/api/upload_box', array('module'=>ROUTE_M));?>')" class="btn btn-primary radius upload-btn"><i class="yzm-iconfont yzm-iconshangchuan"></i> 浏览文件</a>
					</div>
				</div>				
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">打开方式：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<label class="label_radio"><input name="target" type="radio" value="_self" checked> 本窗口打开</label>
						<label class="label_radio"><input name="target" type="radio" value="_blank"> 新窗口打开</label>
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">导航显示：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<label class="label_radio"><input name="display" type="radio" value="1" checked> 是</label>
						<label class="label_radio"><input name="display" type="radio" value="0"> 否</label>
					</div>
				</div>
			</div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">频道页模板：</label>
					<div class="formControls col-xs-8 col-sm-9 yzm-explain-box">
						<span class="select-box" style="width:400px">
						<select name="category_template" id="category_template" class="select">
						  <?php 
						      foreach($category_temp as $key => $val){
									$str = $parent_temp&&$key==$parent_temp['category_template'] ? ' selected="selected" ' : '';
									echo '<option value="'.$key.'"'.$str.'>'.$val.'('.$key.')</option>';
							  }
							  echo $category_temp ? '<option value="">不使用模板</option>' : '<option value="">暂无模板</option>';
						  ?>
						</select>
						</span>
						<span class="yzm-explain">频道页模板命名规则：<br>category_<i class="model_table"><?php echo $tablename;?></i>.html<br> 或 category_<i class="model_table"><?php echo $tablename;?></i>_*.html</span>
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>列表页模板：</label>
					<div class="formControls col-xs-8 col-sm-9 yzm-explain-box">
						<span class="select-box" style="width:400px">
						<select name="list_template" id="list_template" class="select">
						  <?php 
						      foreach($list_temp as $key => $val){
									$str = $parent_temp&&$key==$parent_temp['list_template'] ? ' selected="selected" ' : '';
									echo '<option value="'.$key.'"'.$str.'>'.$val.'('.$key.')</option>';
							  }
							  if(!$list_temp) echo '<option value="">暂无模板</option>';
						  ?>
						</select>
						</span>
						<span class="yzm-explain">列表页模板命名规则：<br>list_<i class="model_table"><?php echo $tablename;?></i>.html<br> 或 list_<i class="model_table"><?php echo $tablename;?></i>_*.html</span>
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>内容页模板：</label>
					<div class="formControls col-xs-8 col-sm-9 yzm-explain-box">
						<span class="select-box" style="width:400px">
						<select name="show_template" id="show_template" class="select">
						  <?php 
						      foreach($show_temp as $key => $val){
									$str = $parent_temp&&$key==$parent_temp['show_template'] ? ' selected="selected" ' : '';
									echo '<option value="'.$key.'"'.$str.'>'.$val.'('.$key.')</option>';
							  }
							  if(!$show_temp) echo '<option value="">暂无模板</option>';
						  ?>
						</select>
						</span>
						<span class="yzm-explain">内容页模板命名规则：<br>show_<i class="model_table"><?php echo $tablename;?></i>.html<br> 或 show_<i class="model_table"><?php echo $tablename;?></i>_*.html</span>
					</div>
				</div>					
			</div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目标题：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="seo_title" value="" placeholder="栏目SEO标题，一般不超过80个字符" class="input-text">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目关键词：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="seo_keywords" value="" placeholder="一般不超过100个字符，多个关键词用英文逗号“,”隔开" class="input-text">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目描述：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<textarea class="textarea" name="seo_description" placeholder="栏目SEO描述，一般不超过200个字符"></textarea>
					</div>
				</div>
			</div>
			<div class="tabCon">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">英文标题：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="entitle" value="" placeholder="英文标题可留空" class="input-text">
					</div>
				</div>		
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目副标题：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="subtitle" value="" placeholder="栏目副标题可留空" class="input-text">
					</div>
				</div>		
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">手机版名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="mobname" value="" placeholder="手机版栏目名称，为空则与电脑端一致" class="input-text">
					</div>
				</div>	
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">绑定域名：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="domain" value="" placeholder="域名格式以http开头" class="input-text">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">栏目排序：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" name="listorder" value="0" class="input-text">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2">允许投稿：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<label class="label_radio"><input name="member_publish" type="radio" value="1"> 是</label>
						<label class="label_radio"><input name="member_publish" type="radio" value="0" checked> 否</label>
					</div>
				</div>				
			</div>

		</div>
		<div class="footer_btn_large">
			<input type="hidden" name="type" value="<?php echo $type;?>">
			<input type="hidden" name="dosubmit" value="1">
			<input class="btn btn-primary radius" type="submit" value="提 交">
			<input class="btn btn-default radius" type="button" value="取 消" onclick="yzmcms_close()">	
		</div>
	</form>
</div>

<?php include $this->admin_tpl('footer');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>js/yzm-pinyin.js"></script> 

<script type="text/javascript">
function yzmcms_pinyin(){
	var catdir = $("input[name='catdir']").val();
	if(catdir == ''){
		var pinyin = codefans_net_CC2PY($("input[name='catname']").val());
		$("input[name='catdir']").val(pinyin.toLowerCase());
	}
	$("input[name='mobname']").val($("input[name='catname']").val());
}

var s = 1;
function change_dir(){
	var pinyin = codefans_net_CC2PY($("input[name='catname']").val());
	pinyin = pinyin.toLowerCase();
	if(s){
		s = 0;
		$("input[name='catdir']").val('<?php echo $parent_dir;?>'+pinyin);	
	}else{
		s = 1;
		$("input[name='catdir']").val(pinyin);	
	}
}

function yzm_change_template(modelid){
	$.ajax({
		type: 'GET',
		url: '<?php echo U('public_category_template');?>?modelid='+modelid, 
		dataType: "json", 
		success: function (msg) {
			var category_template='',list_template='',show_template='';
			var options = '<option value="">暂无模板</option>';
			for(var info in msg.category_template) {
			    category_template += '<option value="'+info+'">'+msg.category_template[info]+'('+info+')</option>';
			}
			for(var info in msg.list_template) {
			    list_template += '<option value="'+info+'">'+msg.list_template[info]+'('+info+')</option>';
			}
			for(var info in msg.show_template) {
			    show_template += '<option value="'+info+'">'+msg.show_template[info]+'('+info+')</option>';
			}
			$('#category_template').html(category_template ? category_template+'<option value="">不使用模板</option>' : options);
			$('#list_template').html(list_template ? list_template : options);
			$('#show_template').html(show_template ? show_template : options);
			$('.model_table').html(msg.tablename);
		}
	})
}

function dosub(obj){
	if($("select[name='modelid']").val()==''){
		layer.msg('请新建模型后再创建栏目！', {icon:2});
		return false;
	}
	var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[-/]){0,29}$/;
	if($("input[name='catname']").val()==''){
		layer.msg('栏目名称不能为空！', {icon:2});
		return false;
	}
	if($("input[name='catdir']").val()==''){
		layer.msg('栏目目录不能为空！', {icon:2});
		return false;
	}
	if(!reg.test($("input[name='catdir']").val())){
		layer.msg('栏目目录只能以英文字符开始，且不能包含特殊字符！', {icon:2});
		return false;
	}
	// if($("select[name='category_template']").val()==''){
	// 	layer.msg('请选择频道页模板！', {icon:2});
	// 	$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","1");
	// 	return false;
	// }
	if($("select[name='list_template']").val()==''){
		layer.msg('请选择列表页模板！', {icon:2});
		$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","1");
		return false;
	}
	if($("select[name='show_template']").val()==''){
		layer.msg('请选择内容页模板！', {icon:2});
		return false;
	}
	var reg = /^http(.+)\/$/;
	var domain = $("input[name='domain']").val();
	if(domain!='' && !reg.test(domain)){
		layer.msg('绑定的栏目域名格式为http://www.yzmcms.com/，请以“/”结尾！', {icon:2});
		return false;
	}
	$.ajax({
		type: 'POST',
		url: '<?php echo U('add');?>', 
		data: $(obj).serialize(),
		dataType: "json", 
		success: function (msg) {
			if(msg.status == 1){
				layer.msg(msg.message, {icon:1,time:1000}, function(){
					parent.location.reload();   
				});
			}else{
				layer.msg(msg.message, {icon:2});
			}
		}
	})
	return false;		
}

$(function(){
	$.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","<?php echo isset($_GET['tab']) ? intval($_GET['tab']) : '0'?>");
});
</script>

</body>
</html>